/*
 * Copyright (c) 2025. hallele, Inc All rights reserved.
 */

package cn.hallele.ms.portalcenter.application.action.menu.query.list.flow;

import cn.dev33.satoken.stp.StpUtil;
import cn.hallele.mc.sdk.portalcenter.common.enums.MenuTypeEnum;
import cn.hallele.ms.portalcenter.application.bo.MenuBO;
import cn.hallele.ms.portalcenter.application.das.MenuBDDas;
import cn.hallele.ms.starter.web.framework.node.ServiceFlow;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;

/**
 * 查询路由
 *
 * @author anle5
 * @since 2025/1/2 22:15
 */
@Slf4j
@LiteflowComponent
public class QueryRouteListFlow extends ServiceFlow {
    @Autowired
    private MenuBDDas menuBDDas;

    @Override
    public void process() throws Exception {
        List<String> roleList = StpUtil.getRoleList();
        List<MenuBO> routesByRoleCodes = menuBDDas.findRoutesByRoleCodes(new HashSet<>(roleList),
                List.of(MenuTypeEnum.MENU, MenuTypeEnum.DIRECTORY, MenuTypeEnum.IFRAME));
        ArrayList<MenuBO> sortMenus = new ArrayList<>(routesByRoleCodes);
        sortMenus.sort(Comparator.comparingInt(MenuBO::getSort));
        this.setResult(sortMenus);
    }
}
